if ('WebSocket' in window){
   //alert("WebSockets are supported.");
} else {
   alert("WebSockets are not supported.");
}

function open(newId, newGame) {
	id = newId;
	game = newGame;
	
	connection = new WebSocket('ws://localhost:8080/MonopolyApp/websocket');
	
	connection.onopen = function(){
	      //alert('Connection open!');
	      connection.send('id:' + id);
	   };

	   connection.onclose = function(){
	      //alert('Connection closed');
	   };

	   connection.onmessage = function(e){
	      var server_message = e.data;
	      //alert(server_message);
	      
	      if (server_message == 'RELOAD') window.location = '?site=playingfield&id=' + game;
	   };
	 
	   connection.onerror = function(e){
		   //alert(e.type + ": " + e.toString());
	   };
}

function send(msg) {
	if (connection.readyState == 0) {
		window.setTimeout("send('" + msg + "')", 50);
	} else {
		connection.send(msg);
	}
}